//
//  SSSPersonalPointsViewController.m
//  SSSMerchant
//
//  Created by xnxin on 2017/3/22.
//  Copyright (c) 2017 xnxin. All rights reserved.
//

#import "SSSPersonalPointsViewController.h"
#import "UIButtonAdditions.h"
#import "XHUIHelper.h"
#import "SSSPersonalPointsViewCellModel.h"

@interface SSSPersonalPointsViewController ()

@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) QMUIButton *currentPointsButton;
@property (nonatomic, strong) UILabel *totalPoinstLabel;

@property (nonatomic, assign) NSInteger currentPoints;
@property (nonatomic, assign) NSInteger totalPoints;

@end

@implementation SSSPersonalPointsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView.tableHeaderView = self.headerView;


    self.tableView.rowHeight = 56;
    self.currentPoints = 0;
    self.totalPoints = 0;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    self.tableView.left = 15;
    self.tableView.width = self.view.width - 30;
}

- (UIView *)headerView {
    if(!_headerView) {

        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, 65)];
        _currentPointsButton = [QMUIButton new];
        _currentPointsButton.normalTitle = @"  当前积分 99999";
        _currentPointsButton.normalImage = [UIImage imageNamed:@"icon_currentintegral"];
        _currentPointsButton.titleLabel.font = [UIFont systemFontOfSize:15];

        [_headerView addSubview:_currentPointsButton];


        _totalPoinstLabel = [UILabel new];
        _totalPoinstLabel.font = [UIFont systemFontOfSize:12];
        _totalPoinstLabel.textColor = [UIColor colorWithHex:@"BBBBBB"];


        [_headerView addSubview:_totalPoinstLabel];

        UIView *line = [XHUIHelper sepreateLineWithY:64.5];
        [_headerView addSubview:line];
        _headerView.clipsToBounds = true;
    }

    return _headerView;
}

- (NSArray<NSString *> *)classNameArray {
    return @[@"SSSPersonalPointsViewCell"];
}


- (NSArray<__kindof XHBaseTableViewCellModel *> *)modelArray {

    SSSPersonalPointsViewCellModel *model = [SSSPersonalPointsViewCellModel new];
    model.percent = 30;
    model.money = [NSDecimalNumber decimalNumberWithString:@"312"];
    model.date = [NSDate date];
    model.sourceType = 1;
    model.username = @"312432148";

    return @[model, model, model, model];
}
#pragma mark -setter
- (void)setCurrentPoints:(NSInteger)currentPoints {
    _currentPoints = currentPoints;
    self.currentPointsButton.normalTitle = [NSString stringWithFormat:@" 当前积分  %ld", (long)currentPoints];
    [self.currentPointsButton sizeToFit];

    self.currentPointsButton.centerX = self.headerView.width/2;
    self.currentPointsButton.top = 15;
}

- (void)setTotalPoints:(NSInteger)totalPoints {
    _totalPoints = totalPoints;

    self.totalPoinstLabel.text = [NSString stringWithFormat:@"(累计积分%ld)", (long)totalPoints];
    [self.totalPoinstLabel sizeToFit];
    self.totalPoinstLabel.centerX = self.headerView.width/2;
    self.totalPoinstLabel.top = self.currentPointsButton.bottom + 8;

}
@end
